package com.edu.compile.dto.http;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.edu.compile.dto.RequestParam;

import java.util.List;

public class HttpParam extends RequestParam<HttpParam> {

    /**
     * 参数名称
     */
    private String paramName;

    /**
     * 参数类型  0-String  1-int  2-long 3-float 4-double 5-boolean
     */
    private Integer paramType;

    /**
     * 是否必填 0-必填项  1-非必填项
     */
    private Integer paramRequired;

    /**
     * 参数默认值
     */
    private String paramDefault;

    /**
     * 参数描述
     */
    private String paramDesc;

    public String getParamName() {
        return paramName;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    public Integer getParamType() {
        return paramType;
    }

    public void setParamType(Integer paramType) {
        this.paramType = paramType;
    }

    public Integer getParamRequired() {
        return paramRequired;
    }

    public void setParamRequired(Integer paramRequired) {
        this.paramRequired = paramRequired;
    }

    public String getParamDefault() {
        return paramDefault;
    }

    public void setParamDefault(String paramDefault) {
        this.paramDefault = paramDefault;
    }

    public String getParamDesc() {
        return paramDesc;
    }

    public void setParamDesc(String paramDesc) {
        this.paramDesc = paramDesc;
    }

    public HttpParam() {
    }

    @Override
    public List<HttpParam> parse(String requestParam) {
        JSONObject jsonObject = JSON.parseObject(requestParam);
        String input = jsonObject.getString("input");
//        List<HttpParam> result = JSON.parseObject(input, new TypeReference<List<HttpParam>>() {
//        }.getType());
//        return result;
        List<HttpParam> result = JSON.parseArray(input, HttpParam.class);
        return result;
    }
}
